//author:jxxgridBody
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import mall_Sign_upactivityBox from "../../views/mall/mall_Sign_upactivityBox.vue";
let extension = {
  components: {
    //动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
    gridBody: mall_Sign_upactivityBox,
    gridFooter: "",
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: "",
    modelBody: "",
    modelFooter: ""
  },
  buttons: {
    view: [
      {
        name: "新建",
        icon: "md-add",
        value: "XJ",
        class: "",
        type: "error",
        index: 1, //显示的位置
        onClick: function() {
          this.$refs.gridBody.model = true;
          this.$refs.gridBody.title = "新建";
          this.$refs.gridBody.GetProductType();
          this.$refs.gridBody.tableData = [];
          this.$refs.gridBody.formFields1.c_name = "";
          this.$refs.gridBody.formFields1.membertype = "";
          this.$refs.gridBody.formFields1.memberlevels = "";
          this.$refs.gridBody.formFields1.isPublic = 0;
          this.$refs.gridBody.formFields1.isShare = 0;
          this.$refs.gridBody.formFields1.picid=[]
          this.$refs.gridBody.formFields1.pics=[]
          this.$refs.gridBody.formFields1.phone = "";
          this.$refs.gridBody.formFields1.groupsize = "";
          this.$refs.gridBody.formFields1.fromId = "";
          this.$refs.gridBody.formFields1.start_time = "";
          this.$refs.gridBody.formFields1.end_time = "";
          this.$refs.gridBody.formFields1.timeContainer = [];
          this.$refs.gridBody.formFields1.timeContainers = [];
          this.$refs.gridBody.formFields1.c_type = "";
          this.$refs.gridBody.formFields1.distributionid = "";
          this.$refs.gridBody.formFields1.isShow = 1;
          this.$refs.gridBody.formFields2.c_remark = "";
          this.$refs.gridBody.formFields2.sellingRulesid = "";
          this.$refs.gridBody.formFields2.refundrulesid = "";
          this.$refs.gridBody.formFields2.verificationrulesid = "";
          this.$refs.gridBody.formFields3.groupsize = "";
          this.$refs.gridBody.formFields3.purchaseseparately = "";
          this.$refs.gridBody.formFields3.virtualclustering = "";
          this.$refs.gridBody.formFields3.maximumvirtualnumber = "";
          this.$refs.gridBody.formFields3.attendancecarddisplay = "";
          this.$refs.gridBody.formFields3.groupeffectivetime = "";
          this.$refs.gridBody.formFields4.preferentialtype = "";
          this.$refs.gridBody.formFields4.c_remark = "";
          this.$refs.gridBody.formFields2.address=""
          this.$refs.gridBody.formFields2 .latitudelongitude=""


        

        }
      },
      {
        name: "编辑",
        icon: "md-create",
        value: "BJ",
        class: "",
        type: "success",
        index: 2,
        onClick: function() {
          if (this.getSelectRows().length == 1) {
            let row = this.getSelectRows()[0];
            // console.log(row);
            this.$refs.gridBody.model = true;
            this.$refs.gridBody.title = "编辑";
            this.getRow(row, 1);
          } else {
            this.$error("只能选中一行进行编辑");
          }
        }
      },
      {
        name: "删除",
        icon: "md-close",
        value: "DEL",
        class: "",
        type: "warning",
        index: 3,
        onClick: function() {
          if (this.getSelectRows().length == 1) {
            let row = this.getSelectRows()[0];
            let params = { ids: [row.c_id] };
            this.$confirm("确定要删除选择的数据吗?", "删除警告", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              // 删除接口
              this.http
                .post("/api/mall_activity/DelActivity", params)
                .then(res => {
                  if (res.status) {
                    this.$Message.error(res.message);
                  } else {
                    this.$Message.success(res.message);
                    this.refresh();
                  }
                  this.model = false;
                });
            });
          } else {
            this.$error("请选择要删除的行");
          }
        }
      }
    ],
    box: [],
    detail: []
  }, //扩展的按钮
  created() {},
  methods: {
    //事件扩展
    getOption(field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        });
      });
      return option;
    },
    onInit() {
      this.$store.getters.data().viewPageTest = this;
      this.single = true;
      this.columns.push({
        field: "",
        title: "操作",
        type: "string",
        width: 100,
        fixed: "right",
        align: "",
        render: (h, { row, column, index }) => {
          return h("div", {}, [
            h(
              "a",
              {
                style: {},
                on: {
                  click: () => {
                    this.$refs.gridBody.box5 = true;
                    console.log(row,"row")
                    this.$refs.gridBody.activeId=row.c_id
                  
                    this.getRow(row)
                  }
                }
              },
              "查看"
            )
            // h(
            //     "el-button",
            //     {
            //         props: {
            //             disabled:
            //                 new Date().getTime() - new Date(row.end_time).getTime() >
            //                 0, // 结束
            //         },
            //         style: {
            //             padding: "5px",
            //             border: "none",
            //         },
            //         on: {
            //             click: () => {
            //                 this.$refs.gridBody.model = true;
            //                 this.$refs.gridBody.title = '编辑'
            //                 this.getRow(row, 1)
            //             },
            //         },
            //     },
            //     "编辑"
            // ),
            // h(
            //     "el-button",
            //     {
            //         props: {
            //             disabled:
            //                 new Date().getTime() - new Date(row.start_time).getTime() >
            //                 0,
            //         },
            //         style: {
            //             padding: "5px",
            //             border: "none",
            //         },
            //         on: {
            //             click: () => {
            //                 let params = { ids: [row.c_id] }
            // this.$confirm("确定要删除选择的数据吗?", "删除警告", {
            //     confirmButtonText: "确定",
            //     cancelButtonText: "取消",
            //     type: "warning",
            // })
            //     .then(() => {
            //         // 删除接口
            //         this.http.post("/api/mall_activity/DelActivity", params).then((res) => {
            //             if (res.status) {
            //                 this.$Message.error(res.message);
            //             } else {
            //                 this.$Message.success(res.message);
            //                 this.refresh()
            //             }
            //             this.model = false;
            //         });
            //     })
            //             },
            //         },
            //     },
            //     "删除"
            // ),
          ]);
        }
      });
    },
    searchBefore(param) {
      let wheres = {
        name: "c_type",
        value: "8",
        displayType: "text"
      };
      param.wheres.push(wheres);
      return true;
    },
    rowClick({ row, column, event }) {
      //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    getproList(id, memberphones, n) {
      let options = {
        order: "desc",
        page: 1,
        rows: 100,
        sort: "membertypeid",
        value: id,
        wheres: "[]"
      };
      this.http.post("/api/MebAccount/getPageData", options).then(res => {
        if (res.rows.length && res.rows.length != 0) {
          let productsList = res.rows.map(i => {
            return {
              label: i.member_name || "",
              value: i.memberid,
              key: i.member_phone,
              disabled: !n
            };
          });
          this.$refs.gridBody.productsList = productsList;
          if (memberphones != "") {
            this.$refs.gridBody.memberphones = memberphones.split(",");
          }
        }
      });
    },
    getRow(v, n) {
      this.$refs.gridBody.formFields1.timeContainer = [
        v.start_time,
        v.end_time
      ];
      let params = {
        page: 1,
        rows: 30,
        order: "desc",
        wheres: "[]",
        value: v.c_id
      };
      this.http.post("api/mall_activity/GetApplicationGetDetailPage", params).then(res => {
        this.$refs.gridBody.ZB = v;
        let FormID= JSON.parse( JSON.stringify(res.rows) );
        console.log(FormID,"FormID")
        if(FormID.length>0){
          let FormArr=[]
          FormID.forEach(item=>{
            FormArr.push(item.fromId)  
          })
        let param = {"page":1,"rows":30,"sort":"id","order":"desc",
        "wheres":`[{\"name\":\"form_type\",\"value\":\"3\",\"displayType\":\"select\"},{\"name\":\"id\",\"value\":\"${FormArr.toString()}\",\"displayType\":\"checkbox\"}]`}
        this.http.post("/api/Form/getPageData", param).then(res => {
          // console.log(res.rows,"FormID")
            this.$refs.gridBody.headerNameLists=res.rows
            
        })}
        // this.$refs.gridBody.headerNameList=res.rows
        let relationshipInfo = res.rows;
        let children = {};
        relationshipInfo.forEach((item, index) => {
          let {activity_session,activity_session_date } = item;
          if (!children[activity_session]) {
            children[activity_session] = {
              activity_session,
              activity_session_date,
              children: []
            };
          }
          children[activity_session].children.push(item);
        });
        let list = Object.values(children); // list 转换成功的数据
        list.forEach((item)=>{
          item.activity_session_date=  item.activity_session_date==""?[]:JSON.parse(item.activity_session_date) 
          item.children.forEach((t)=>{
           t. membertype= t.membertype==[]?"":JSON.parse(t.membertype)
           t. memberlevels= t.memberlevel==[]?"":JSON.parse(t.memberlevel)
           t.activity_session_date=  t.activity_session_date==""?[]:JSON.parse(t.activity_session_date) 
          })
        })
       console.log(list,"list")
        this.$refs.gridBody.tableData = list;
        // this.$refs.gridBody.goodsListInfo = res.rows;
      });
      
      this.$refs.gridBody.formFields1.distributionid = v.distributionid.toString();
      this.$refs.gridBody.formFields1.c_name = v.c_name;
      this.$refs.gridBody.formFields1.start_time = v.start_time;
      this.$refs.gridBody.formFields1.end_time = v.end_time;
      this.$refs.gridBody.formFields1.c_type = v.c_type.toString();
      this.$refs.gridBody.formFields1.isShow = v.isShow;
      switch (v.c_type) {
        case 0:
          this.$refs.gridBody.formFields2.refundrulesid = v.refundrulesid;
          this.$refs.gridBody.formFields2.verificationrulesid =
            v.verificationrulesid;
          this.$refs.gridBody.formFields2.sellingRulesid = v.sellingRulesid;
          this.$refs.gridBody.formFields2.c_remark = v.c_remark;
          break;
        case 1:
          this.$refs.gridBody.formFields3.groupsize = v.groupsize;
          this.$refs.gridBody.formFields3.purchaseseparately =
            v.purchaseseparately;
          this.$refs.gridBody.formFields3.virtualclustering =
            v.virtualclustering;
          this.$refs.gridBody.formFields3.maximumvirtualnumber =
            v.maximumvirtualnumber;
          this.$refs.gridBody.formFields3.attendancecarddisplay =
            v.attendancecarddisplay;
          this.$refs.gridBody.formFields3.groupeffectivetime =
            v.groupeffectivetime;
          break;
        case 2:
          this.$refs.gridBody.formFields4.preferentialtype = v.preferentialtype.toString();
          this.$refs.gridBody.setprefreialtems(JSON.parse(v.preferentialterms));
          this.$refs.gridBody.formFields4.c_remark = v.c_remark;
          break;
        case 3:
          this.$refs.gridBody.formFields4.preferentialtype = v.preferentialtype.toString();
          this.$refs.gridBody.setprefreialtems(JSON.parse(v.preferentialterms));
          this.$refs.gridBody.formFields4.c_remark = v.c_remark;
          break;
        case 5:
          this.$refs.gridBody.tableData = JSON.parse(v.rechargeRules);
          break;
        case 6:
          this.$refs.gridBody.tableData = JSON.parse(v.rechargeRules);
          break;
        case 7:
          this.$refs.gridBody.tableData = JSON.parse(v.rechargeRules);
          break;
        case 8:
          this.getproList(v.membertypes, v.memberphones, n);
          this.$refs.gridBody.formFields1.groupsize = v.groupsize;
          this.$refs.gridBody.formFields1.activitysort = v.activitysort;
          this.$refs.gridBody.formFields2.address = v.address;
          this.$refs.gridBody.formFields2.latitudelongitude =
            v.latitudelongitude;
          this.$refs.gridBody.formFields1.fromId = v.fromId;
          this.$refs.gridBody.formFields1.phone = v.phone;
          this.$refs.gridBody.formFields1.isPublic=v.isPublic
          this.$refs.gridBody.formFields1.isShare=v.isShare
           if(v.picid!=""){
            this.$refs.gridBody.formFields1.picid=JSON.parse(v.picid)
            this.$refs.gridBody.formFields1.pics=JSON.parse(v.pics)
          }
          if(v.pics!=""){
            this.$refs.gridBody.formFields1.pics=JSON.parse(v.pics)
          }
            // if(v.memberlevels!=""){
          //   console.log(typeof(v.memberlevels),v.memberlevels,this.$refs.gridBody.formFields1,"(v.memberlevels")
          // this.$refs.gridBody.formFields1.memberlevels= v.memberlevels.split(",").map((item) => item * 1)}
          // })
          // if(v.membertypes!=""){this.$refs.gridBody.formFields1.membertype= v.membertypes.split(",").map((item) => item * 1)}
          // console.log(this.$refs.gridBody.formFields1.membertype,"this.$refs.gridBody.formFields1.membertype")
          // Number(v.membertypes) [45,47,44]
          // this.$nextTick(()=>{
          // if(v.memberlevels!=""){
          //   console.log(typeof(v.memberlevels),v.memberlevels,this.$refs.gridBody.formFields1,"(v.memberlevels")
          // this.$refs.gridBody.formFields1.memberlevels= v.memberlevels.split(",").map((item) => item * 1)}
          // })
          this.$refs.gridBody.formFields2.refundrulesid = v.refundrulesid;
          this.$refs.gridBody.formFields2.verificationrulesid =
            v.verificationrulesid;
          this.$refs.gridBody.formFields2.sellingRulesid = v.sellingRulesid;
          this.$refs.gridBody.formFields2.c_remark = v.c_remark;
          this.$refs.gridBody.formFields1.timeContainers = [
            v.application_starttime,
            v.application_endtime
          ];
          // this.$refs.gridBody.formFields1.fromId = Number(v.fromId);
          break;
      }
    }
  }
};
export default extension;
